#!/bin/bash
sleep 5

systemctl restart mariadb

sleep 3

# mariadb初始化
if [ -z "$MARIADB_HOME" ]; then
  # 初始化mariadb用户和数据库
  mysql -e "CREATE database `simple` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
  mysql -e "create user 'simple'@'%' identified by 'simple';"
  mysql -e "grant all on `simple`.* to 'simple'@'%' identified by 'simple';"
  mysql -e "flush privileges;"
  # 执行初始化应用数据库脚本
  mysql -e "use simple; source /opt/simple.sql;";
  # 初始化数据库
  echo -e "\nn" | mysql_secure_installation
  echo "export MARIADB_HOME=/var/lib/mysql" >> /etc/rc.d/rc.local
fi

# 启动zookeeper
/opt/apache-zookeeper-3.7.0-bin/bin/zkServer.sh restart

# 隐式启动user-service
nohup java -jar /opt/simple-user-service.jar > /dev/null &

nohup java -jar /opt/simple-gateway.jar --server.port=8080 > /dev/null &